home *** CD-ROM | disk | FTP | other *** search
- Path: mozo.cc.purdue.edu!not-for-mail
- From: hrubin@b.stat.purdue.edu (Herman Rubin)
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Subject: Re: Access carry flag from C
- Date: 5 Mar 1996 07:26:16 -0500
- Organization: Purdue University Statistics Department
- Message-ID: <4hhbt8$1d3o@b.stat.purdue.edu>
- References: <Dn1C9z.DGv.0.net@indra.com> <825377932snz@genesis.demon.co.uk> <4h1veoINNlns@anvil.ugrad.cs.ubc.ca> <fgrieu-0403961143580001@ppp78.micronet.fr>
- NNTP-Posting-Host: b.stat.purdue.edu
-
- In article <fgrieu-0403961143580001@ppp78.micronet.fr>,
- Franτois Grieu <fgrieu@micronet.fr> wrote:
- >In article <Dn1C9z.DGv.0.net@indra.com>,
- >Steve Sullivan <sullivan@indra.com> wrote:
-
- >> Is it possible to determine if a fixed point overflow has
- >> occurred from within C? For example:
- >> i = j + k;
- >> if (overflowed) ....;
-
- >For the purprose of doing multiple precision arithmetic, the following
- >trick works across many machines and compilers, including 80x86, 680x0, PPCs
-
- >unsigned long yl,yh; /* double_unsigned_long_int y */
- >unsigned long x;
-
- >/* add x to double_unsigned_long_int variable y */
- > if (x + yl < yl) ++yh; /* test for overflow on next line */
- > yl += x;
-
-
- >(I missed a lot of this thread, so maybe this has already been posted)
-
- This will work, but slowly. Anything can be done on any machine in any
- language, if one works hard enough, and has enough memory.
-
- Notice that in the above code, each addition must be performed twice.
- BTW, there is a weakness in the code; ++yh can cause a carry, so
- another test is needed. As testing is expensive, what is needed in
- this case is not a test for carry, but the ability to add the carry
- bit to something. If you check this out, you will see that this can
- be done.
- --
- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
- hrubin@stat.purdue.edu Phone: (317)494-6054 FAX: (317)494-0558
-